/**
 * 添加收货地址
 * @param data 请求参数
 */
export const postMemberAddressAPI = (data: any) => {
  return {
    method: 'POST',
    url: '/address/create',
    data,
  }
}

/**
 * 获取收货地址列表
 */
export const getMemberAddressAPI = () => {
  return {
    method: 'GET',
    url: '/address/list',
  }
}

/**
 * 获取收货地址详情
 * @param id 地址id(路径参数)
 */
export const getMemberAddressByIdAPI = (id: string) => {
  return {
    method: 'GET',
    url: `/address/${id}`,
  }
}

/**
 * 修改收货地址
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const putMemberAddressByIdAPI = (id: string, data: any) => {
  return {
    method: 'PUT',
    url: `/address/${id}`,
    data,
  }
}

/**
 * 删除收货地址
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
  return {
    method: 'DELETE',
    url: `/address/${id}`,
  }
}

import mockRes from '@/mock/address.json'
import type { AddressItem } from '@/types/address'

// 模拟获取会员地址数据
export const getMemberAddressData = async (): Promise<AddressItem[]> => {
  // 模拟网络延迟
  await new Promise((resolve) => setTimeout(resolve, 300))
  if (mockRes.code === '200') {
    return mockRes.data as AddressItem[]
  } else {
    return []
  }
}
